package shejimoshi.zuhemoshi;

import java.util.ArrayList;
import java.util.List;

// 容器节点实现
public class Composite extends Component {
    public List<Component> children = new ArrayList<>();

    // 添加子组件
    public void add(Component component) {
        children.add(component);
    }

    // 移除子组件
    public void remove(Component component) {
        children.remove(component);
    }

    // 实现抽象方法
    @Override
    public void operation() {
        for (Component component : children) {
            component.operation();
        }
    }
}
